﻿// <copyright file="admin_Logs_View.aspx.cs" company="NTalent">
// Copyright (c) 2010, NTalent, Inc. All rights reserved
// </copyright>
// <author>卢俊坤</author>
// <author>王彦博 符茂松</author>

using System;
using System.Web.UI.WebControls;
using Net.Ntalent.Action50.Core.Controls;
using Net.Ntalent.Action50.Core.Util;
using Net.Ntalent.Action50.Core.Service;
using Net.Ntalent.Action50.Core.Dao;

/// <summary>
/// 管理页面，浏览某个action的所有log
/// </summary>
///<author>王彦博</author> 
/// <copyright>
/// Copyright (c) 2010, NTalent, Co. Ltd. All rights reserved.
/// </copyright>
/// <version>1.0.0</version>
public partial class admin_Logs_View : PageBase
{
    public admin_Logs_View()
    {
        //设置权限，使未登录用户不能访问该页
        authentication = Constants.AUTHENTICATION_ADMIN;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// Logout
    /// </summary>
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        AuthenticationService authenticationService = new AuthenticationService();
        authenticationService.LogOut();
        Response.Redirect(Request.UrlReferrer.ToString());
    }

    protected void ListView1_DataBound(object sender, EventArgs e)
    {
        //如果数据不够一页，则不显示分页控件。
        var readOnlyService = new ReadOnlyService();
        long logsCount = readOnlyService.RetrieveActionLogs(Convert.ToInt64(Helper.getQueryString(Context, "actionId"))).Count;
        if (logsCount <= 15)
        {
            DataPager1.Visible = false;
        }
    }
    /// <summary>
    /// 将logs按发表时间照降序排列
    /// </summary>
    protected void btn_sortdown_Click(object sender, EventArgs e)
    {
        ObjectDataSource1.SelectParameters["orderby"].DefaultValue = "POST_DATETIME DESC";
        ListView1.DataBind();
    }

    /// <summary>
    /// 将logs按照发表时间升序排列
    /// </summary>
    protected void btn_sortup_Click(object sender, EventArgs e)
    {
        ObjectDataSource1.SelectParameters["orderby"].DefaultValue = "POST_DATETIME";
        ListView1.DataBind();
    }

    /// <summary>
    /// 删除某个log
    /// </summary>
    protected void DeleteAction(object sender, EventArgs e)
    {
        //点击删除之后，用js将欲删除的项的id写入一个HiddenField，弹出提示框.
        //点击确认后调用该方法，从HiddenField中读取欲删除的项的ID
        long logsId = Convert.ToInt64(HiddenField_actionToBeDelete.Value);
        new NewsAndLogsDao().Delete(logsId);
        ListView1.DataBind();
    }
}
